/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ThreadBasedSimulator;

/**
 *
 * @author mahesh
 */
public class Clock extends Thread
{

    public Clock()
    {
        m_nTimePeriod = 100;
    }
    
    @Override
    public void run() {
        while( true )
        {
           
            
            try
            {
                // sleep for a while
                Thread.sleep(m_nTimePeriod);
                
                // wake up all the threads that are waiting for the clock
             
                synchronized(this)
                {
                    try
                    {
                        notifyAll();
                        
                    }
                    catch(Exception e)
                    {
                        System.out.println(" Exception in Clock.notify : " + e);
                    }
                }
            }
            catch( Exception e )
            {
                System.out.println( "Exception in Clock.run : " + e );
            }
            
        }
    }
    // the period of the cloc in ms
    private int             m_nTimePeriod;      
    //private ProcessorThread threadProcessor;
    //private MemoryThread    threadMemory;
    //private IOThread        threadIO;
}
